<?php
/*
 * Joomla! 1.5 component ArticleCashRewards
 *
 * @version $Id: reports.php 2009-05-10 01:47:01 svn $
 * @author Maverick
 * @package controllers
 * @subpackage ArticleCashRewards
 * @license GNU/GPL
 * Website: http://www.boddunan.com
 *
 * Review and approve the articles and assign points and cash rewards.
 * Users can see their articles and the points/cash rewards assigned in the front-end module.
 */

defined('_JEXEC') or die();

class ArticleCashRewardsControllerReports extends ArticleCashRewardsController
{

	function __construct($config = array()){
		parent::__construct($config);
        global $mainframe, $acr_config;
        $acr_config = $mainframe->getUserState( SESSION_ACR_CONFIG );

        if(!isset($acr_config)){
            $model = & $this->getModel('config');
            $configt = $model->getConfiguration();

            foreach($configt as $ct){
                $acr_config[$ct->config_name] = $ct->config_value;
            }
            $mainframe->setUserState( SESSION_ACR_CONFIG, $acr_config );
        }
        $this->registerTask( 'userearnings','userEarnings' );
        $this->registerTask( 'pendingpayments','getPendingPayments' );
        $this->registerTask( 'runpayments','runPayReports' );
        $this->registerTask( 'makepay','processPayments' );
        $this->registerTask( 'processed','getProcessedPayments' );
        $this->registerTask( 'recalcpage','pageRecalc' );
        $this->registerTask( 'recalculate','recalculateEarnings' );
        $this->registerTask( 'syncaup','synchronizeAUPoints' );
        $this->registerTask( 'cpanel','cPanel' );
        $this->registerTask( 'default', 'display' );
	}

    function display(){
        JRequest::setVar( 'view', 'reports' );
        parent::display();
    }

    function userEarnings(){
		$view = & $this->getView('reports', 'html');
		$model = & $this->getModel('reports');
		$view->setModel($model, true);
        $view->setLayout('userearnings');
        $view->display();
    }

    function pageRecalc(){
		$view = & $this->getView('reports', 'html');
        $view->setLayout('recalcpage');
        $view->display();
    }

    function getPendingPayments(){
		$view = & $this->getView('reports', 'html');
		$model = & $this->getModel('reports');
		$view->setModel($model, true);
        $view->setLayout('pendingpayments');
        $view->display();
    }

    function getProcessedPayments(){
		$view = & $this->getView('reports', 'html');
		$model = & $this->getModel('reports');
		$view->setModel($model, true);
        $view->setLayout('processed');
        $view->display();
    }

    function synchronizeAUPoints(){
		$model	= &$this->getModel( 'reports' );
        $model->syncAup();

		$view = & $this->getView('reports', 'html');
		$view->setModel($model, true);
        $view->setLayout('userearnings');
        $view->display();
    }
    
    function recalculateEarnings(){
		$model	= &$this->getModel( 'reports' );
        $model->recalculateEarnings(null);

		$view = & $this->getView('reports', 'html');
		$view->setModel($model, true);
        $view->setLayout('userearnings');
        $view->display();
    }

    function runPayReports(){
		$model	= &$this->getModel( 'reports' );
        $model->runPaymentReports();

		$view = & $this->getView('reports', 'html');
		$view->setModel($model, true);
        $view->setLayout('pendingpayments');
        $view->display();
    }

    function processPayments(){
        global $option, $mainframe;
		$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
		if (count($cid) < 1) {
			$msg =  JText::_('Select an item to delete');
			$mainframe->redirect('index.php?option='.$option, $msg, 'error');
		}
		$model	= &$this->getModel( 'reports' );
        $model->processPayments($cid);
        
		$view = & $this->getView('reports', 'html');
		$view->setModel($model, true);
        $view->setLayout('pendingpayments');
        $view->display();
    }
    
    function cPanel(){
		
        $link = 'index.php?option=com_articlecashrewards&controller=cpanel';
        $this->setRedirect($link);
	}
}
?>
